<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <!-- <script src="../src/data.js"></script> -->
    <style>
      body {
        margin: 0;
        padding: 0;
      }

      .username {
        position: absolute;
        left: 347px;
        top: 250px;
        border-radius: 5px;
        height: 24px;
      }

      button {
        background: transparent;
        outline: none;
        border: none;
        color: white;
      }

      .heroShow {
        width: 50px;
        height: 50px;
      }

      .sub {
        position: absolute;
        left: 351px;
        top: 288px;
        width: 126px;
        color: white;
        font-weight: bold;
        font-size: 18px;
      }

      .geme {
        position: relative;
      }

      .heroBtn {
        position: absolute;
        left: 45px;
        top: 8px;
        font-size: 14px;
      }

      .skinBtn {
        position: absolute;
        top: 8px;
        left: 105px;
        font-size: 14px;
      }

      .userView {
        position: absolute;
        /* width: 80px; */
        top: 34px;
        left: 720px;
      }

      .userView img {
        width: 40px;
        height: 40px;
      }

      .chioseusername {
        display: block;
        color: rgb(255, 215, 0);
        text-align: center;
        font-size: 12px;
        font-weight: bold;
      }

      .skillsView {
        position: absolute;
        display: flex;
        flex-direction: column;
        left: 660px;
        top: 200px;
      }

      .skillsView img {
        display: none;
        width: 40px;
        height: 40px;
        margin-bottom: 10px;
      }

      .heroView {
        width: 120px;
        position: absolute;
        margin-top: 40px;
        margin-left: 20px;
        display: flex;
        flex-wrap: wrap;
      }

      .skinView {
        width: 130px;
        position: absolute;
        margin-top: 40px;
        margin-left: 20px;
        display: flex;
        flex-wrap: wrap;
      }

      .heroView img {
        width: 50px;
        height: 50px;
      }

      .skinView img {
        width: 50px;
        height: 50px;
      }

      .heroItem {
        margin-left: 10px;
        margin-top: 10px;
        display: flex;
        flex-direction: column;
        color: gray;
        align-items: center;
        font-size: 12px;
      }

      .skinItem {
        margin-left: 10px;
        margin-top: 10px;
        display: flex;
        flex-direction: column;
        color: gray;
        align-items: center;
        font-size: 12px;
      }
      .heroShow img {
        display: none;
      }
      .skinShow {
        position: absolute;
        left: 320px;
        top: 40px;
      }
      .skinShow img {
        display: none;
      }

      .login {
        display: block;
      }

      .game {
        display: none;
      }

      .heroContainer {
        display: block;
      }

      .skinContainer {
        display: none;
      }
    </style>
  </head>

  <body>
    <!-- 登录页面 -->
    <div class="login">
      <input class="username" /> <button class="sub">登录</button>
      <img src="./sources/login.JPG" alt="" />
    </div>
    <!-- 游戏选择页面 -->
    <div class="game">
      <button class="heroBtn">英雄</button>
      <div class="heroContainer">
        <div class="heroView">
          <div class="heroItem">
            <img src="./sources/heroes/yase1.png" />
            <span>亚瑟</span>
          </div>
          <div class="heroItem">
            <img src="./sources/heroes/luban1.png" />
            <span>鲁班</span>
          </div>
        </div>
      </div>

      <button class="skinBtn">皮肤</button>
      <div class="skinContainer">
        <div class="skinView">
          <div class="skinItem">
            <img src="./sources/heroes/yase1.png" />
            <span>经典</span>
          </div>
          <div class="skinItem">
            <img src="./sources/heroes/yase2.png" />
            <span>死亡骑士</span>
          </div>
        </div>
      </div>

      <div class="skinShow">
        <img src="./sources/skins/301660.png" alt="" />
      </div>
      <div class="userView">
        <div class="heroShow">
          <img src="./sources/heroes/yase1.png" />
        </div>
        <span class="chioseusername">张三</span>
      </div>

      <div class="skillsView">
        <img src="./sources/skills/11210.png" />
        <img src="./sources/skills/11220.png" />
        <img src="./sources/skills/11230.png" />
      </div>
      <div></div>
      <img src="./sources/chiose.JPG" />
    </div>
    <script type="module">
      import { data } from "./src/data.js";

      let skillsView = document.querySelectorAll(".skillsView img");
      let skinBtn = document.querySelector(".skinBtn");
      let loginBtn = document.querySelector(".sub");
      let login = document.querySelector(".login");
      let game = document.querySelector(".game");
      let heroShow = document.querySelector(".heroShow img");
      let smallEles = document.querySelectorAll(".heroItem");
      let skinShow = document.querySelector(".skinShow img");

      heroShow.src = "";
      loginBtn.onclick = function () {
        let input = document.querySelector(".username").value;
        login.style.display = "none";
        game.style.display = "block";
        document.querySelector(".chioseusername").innerHTML = input;
      };

      skinBtn.onclick = function () {
        if (
          heroShow.src ==
          "http://127.0.0.1:5500/3.11/%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6%E6%A8%A1%E5%9D%97%E5%8C%96/sources/heroes/yase1.png"
        ) {
          for (let j in data.亚瑟.src.small[1]) {
            smallEles[0].querySelector("span").innerHTML = j;
            smallEles[0].querySelector("img").src = data.亚瑟.src.small[1][j];
          }
          for (let j in data.亚瑟.src.small[2]) {
            smallEles[1].querySelector("span").innerHTML = j;
            smallEles[1].querySelector("img").src = data.亚瑟.src.small[2][j];
          }
        } else if (
          heroShow.src ==
          "http://127.0.0.1:5500/3.11/%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6%E6%A8%A1%E5%9D%97%E5%8C%96/sources/heroes/luban1.png"
        ) {
          for (let j in data.鲁班.src.small[1]) {
            smallEles[0].querySelector("span").innerHTML = j;
            smallEles[0].querySelector("img").src = data.鲁班.src.small[1][j];
          }
          for (let j in data.鲁班.src.small[2]) {
            smallEles[1].querySelector("span").innerHTML = j;
            smallEles[1].querySelector("img").src = data.鲁班.src.small[2][j];
          }
        }
      };
      document.querySelector(".heroBtn").onclick = function () {
        if (
          heroShow.src ==
          "http://127.0.0.1:5500/3.11/%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6%E6%A8%A1%E5%9D%97%E5%8C%96/sources/heroes/yase1.png"
        ) {
          for (let j in data) {
            smallEles[1].querySelector("span").innerHTML = "鲁班";
            smallEles[1].querySelector("img").src = data.鲁班.src.small[0].经典;
            smallEles[0].querySelector("span").innerHTML = "亚瑟";
            smallEles[0].querySelector("img").src = data.亚瑟.src.small[0].经典;
            click();
          }
        } else if (
          heroShow.src ==
          "http://127.0.0.1:5500/3.11/%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6%E6%A8%A1%E5%9D%97%E5%8C%96/sources/heroes/luban1.png"
        ) {
          for (let j in data) {
            smallEles[1].querySelector("span").innerHTML = "鲁班";
            smallEles[1].querySelector("img").src = data.鲁班.src.small[0].经典;
            smallEles[0].querySelector("span").innerHTML = "亚瑟";
            smallEles[0].querySelector("img").src = data.亚瑟.src.small[0].经典;
            click();
          }
        }
      };

      function toBe(鲁班, a) {
        let skinShow = document.querySelector(".skinShow img");
        let heroShow = document.querySelector(".heroShow img");
        let skillsView = document.querySelectorAll(".skillsView img");
        skinShow.style.display = "block";
        heroShow.style.display = "block";
        heroShow.src = data[鲁班].src.small[0].经典;
        skinShow.src = data[鲁班].src.skins[a];
        for (let i = 0; i < skillsView.length; i++) {
          skillsView[i].style.display = "block";
          skillsView[i].src = data[鲁班].src.skill[i];
        }
      }
      click();
      function click() {
        let smallEles = document.querySelectorAll(".heroItem");
        smallEles.forEach((item) => {
          item.onclick = function () {
            if (item.lastElementChild.innerHTML == "亚瑟") {
              toBe("亚瑟", 0);
            } else if (item.lastElementChild.innerHTML == "鲁班") {
              toBe("鲁班", 0);
            } else if (item.lastElementChild.innerHTML == "木偶奇遇") {
              skinShow.src = data.鲁班.src.skins[1];
            } else if (item.lastElementChild.innerHTML == "福禄兄弟") {
              skinShow.src = data.鲁班.src.skins[2];
            } else if (item.lastElementChild.innerHTML == "死亡骑士") {
              skinShow.src = data.亚瑟.src.skins[1];
            } else if (item.lastElementChild.innerHTML == "狮心王") {
              skinShow.src = data.亚瑟.src.skins[2];
            }
          };
        });
      }
    </script>
  </body>
</html>
